You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
922 B
31 lines
922 B
import { defineWrappedResponseHandler } from "#server/utils/handler";
|
|
import { R } from "#server/utils/response";
|
|
import { requireAdmin } from "#server/utils/admin-guard";
|
|
import {
|
|
getCharacterCardBySlugAny,
|
|
updateCharacterCard,
|
|
type UpdateCharacterCardInput,
|
|
} from "#server/service/character/character-card";
|
|
|
|
export default defineWrappedResponseHandler(async (event) => {
|
|
await requireAdmin(event);
|
|
|
|
const slug = getRouterParam(event, "slug");
|
|
if (!slug) {
|
|
return R.error("参数无效", null);
|
|
}
|
|
const card = await getCharacterCardBySlugAny(slug);
|
|
if (!card) {
|
|
return R.error("角色不存在", null);
|
|
}
|
|
|
|
const body = await readBody(event);
|
|
const input = body as UpdateCharacterCardInput;
|
|
|
|
try {
|
|
const updated = await updateCharacterCard(card.id, input);
|
|
return R.success(updated);
|
|
} catch (e) {
|
|
return R.error(e instanceof Error ? e.message : String(e), null);
|
|
}
|
|
});
|
|
|